<script setup name="Person" lang="ts">
import {watch, ref} from "vue";

// 数据
let sum = ref(0);

//方法
const changeSum = () => {
  sum.value++;
}

//监听
const stopWatch = watch(sum, (newValue, oldValue) => {
  console.log("sum变化了 ==>", "现在的值：" + newValue, "之前的值：" + oldValue);
  // 当sum大于等于 10 时，停止监视
  if (newValue >= 10) {
    stopWatch();
  }
})
// console.log("stopWatch：",stopWatch);

</script>

<template>
  <div class="person">
    <h1>情况一：监视【ref】定义的【基本类型】数据</h1>
    <h2>当前求和为：{{ sum }}</h2>
    <button @click="changeSum">点我sum+1</button>
  </div>
</template>

<style scoped>
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px #000;
  border-radius: 10px;
  padding: 20px;
}

button {
  margin: 0 5px;
}

li {
  font-size: 20px;
}
</style>
